import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

class HTPageControl extends StatelessWidget {

  final int numberOfPages;
  final int currentPage;
  final Color pageColor;
  final Color tintColor;
  final double space;
  final double height;
  final double pageWidth;
  final double pageHeight;
  final double currentPageWidth;
  final double currentPageHeight;
  final double radius;
  final Axis scrollDirection;

  HTPageControl({
    // 高度 必传
    required this.height,
    // 总页数 必传
    required this.numberOfPages,
    // 当前页数
    this.currentPage = 0,
    // 未选颜色 默认灰色
    this.pageColor = Colors.grey,
    // 选中颜色 默认白色
    this.tintColor = Colors.white,
    // 间隔 默认5
    this.space = 5,
    // 指示器宽度 默认5
    this.pageWidth = 5,
    // 指示器高度 默认5
    this.pageHeight = 5,
    // 选中指示器宽度 默认5
    this.currentPageWidth = 5,
    // 选中指示器高度 默认5
    this.currentPageHeight = 5,
    // 指示器圆角度 默认2
    this.radius = 2,
    // 排序的方向 默认横着排序
    this.scrollDirection = Axis.horizontal,

    Key? key,
  }) : super( key: key);

  @override
  Widget build(BuildContext context) {
    return Container(
      height: height,
      child: ListView.builder(
        shrinkWrap: true,
        scrollDirection: scrollDirection,
        itemCount: numberOfPages,
        itemBuilder: ((context, index) {
          double currentSpace = space;
          if (index == numberOfPages - 1) {
            currentSpace = 0;
          }
          if (index == currentPage) {
            return Center(
              child: Container(
                margin: new EdgeInsets.fromLTRB(0, 0, scrollDirection == Axis.horizontal ? currentSpace : 0, scrollDirection != Axis.horizontal ? currentSpace : 0),
                width: currentPageWidth,
                height: currentPageHeight,
                decoration: BoxDecoration(
                  borderRadius: BorderRadius.all(Radius.circular(radius)),
                  color: tintColor,
                ),
              ),
            );
          }
          return Center(
            child: Container(
              margin: new EdgeInsets.fromLTRB(0, 0, scrollDirection == Axis.horizontal ? currentSpace : 0, scrollDirection != Axis.horizontal ? currentSpace : 0),
              width: pageWidth,
              height: pageHeight,
              decoration: BoxDecoration(
                color: pageColor,
                borderRadius: BorderRadius.all(Radius.circular(radius)),
              ),
            ),
          );
        }),
      ),
    );
  }
}